<?php
namespace app\common\logic;

use think\facade\Db;
use think\Session;

class SupplyLogic
{
    public function login($username, $password)
    {
        if (empty($username) || empty($password)) {
            return ['status' => 0, 'msg' => '请填写账号密码'];
        }

        $condition['a.user_name'] = $username;
        $condition['a.password'] = encrypt($password);
        $supply = Db::name('supplyliers')->alias('s')->where($condition)->find();
        if (!$supply) {
            return ['status' => 0, 'msg' => '账号密码不正确'];
        }
        $this->handleLogin($supply);
        $url = url('admin/Index/index');
        return ['status' => 1, 'url' => $url];
    }

    public function handleLogin($supply, $actList)
    {
        Db::name('supplyliers')->where('id', $supply['id'])->save([
            'last_login' => time(),
            'last_ip' => request()->ip()
        ]);

        session('act_list', 0);
        session('admin_name', $supply['nickname']);
        session('s_id', $supply['id']);
        session('expire_time',time()+86400);
        session('suppliers_id', $supply['id']);

    }
}






